<?php
function data_tersedia($table, $kd_perkara) {;
	$dt = mysql_num_rows(mysql_query("SELECT kd_perkara FROM $table WHERE kd_perkara='$kd_perkara'"));
	if($dt >= 1) {
		return true;
	}
}

function jml_tersangka($kd_perkara) {
	$q_tersangka = mysql_query("SELECT * FROM t_tersangka_spdp WHERE kd_perkara='$kd_perkara'");
	$t_tersangka = mysql_num_rows($q_tersangka);
		
	if($t_tersangka > 2) {
		return ", DKK";
	} elseif($t_tersangka == 2) {
		return ", CS";
	} else {
		return "";
	}
}

function perkara_register() {
	$cari = pengaturan('kd_instansi').date("Y");
	$dt = mysql_fetch_array(mysql_query("SELECT kd_perkara FROM t_perkara WHERE kd_perkara LIKE '$cari%' ORDER BY kd_perkara DESC limit 1"));
	$akhir = substr($dt[0], -4);
	return $cari.str_repeat("0", 4 - strlen($akhir+1)).($akhir+1);
}

function perkara_tersedia($kd_perkara, $tabel) {;
	$dt = mysql_num_rows(mysql_query("SELECT kd_perkara FROM &tabel WHERE kd_perkara='$kd_perkara'"));
	if($dt==1) {
		return true;
	}
}

function p16_register($pidana) {
	$dt = mysql_fetch_array(mysql_query("SELECT no_surat FROM t_p16 WHERE kd_pidana=$pidana AND tgl_dikeluarkan LIKE '".date("Y")."%' ORDER BY no_surat DESC limit 1"));
	return str_repeat("0", 4 - strlen($dt[0]+1)).($dt[0]+1);
}

function p17_tampil($tanggal) {
	$tgl = explode("-",$tanggal);
	return true;
}

// function register penuntutan.....
function p16a_register($pidana) {
	$dt = mysql_fetch_array(mysql_query(
		"SELECT a.no_surat 
		FROM t_p16a a
		LEFT JOIN t_p16 b ON a.kd_perkara = b.kd_perkara
		WHERE b.kd_pidana=$pidana AND a.tgl_dikeluarkan LIKE '".date("Y")."%' 
		ORDER BY a.no_surat DESC limit 1"));
	return str_repeat("0", 4 - strlen($dt[0]+1)).($dt[0]+1);
}

function t7_register($pidana) {
	$dt = mysql_fetch_array(mysql_query(
		"SELECT a.no_surat 
		FROM t_t7 a
		LEFT JOIN t_p16 b ON a.kd_perkara = b.kd_perkara
		WHERE b.kd_pidana=$pidana AND a.tgl_dikeluarkan LIKE '".date("Y")."%' 
		ORDER BY a.no_surat DESC limit 1"));
	return str_repeat("0", 4 - strlen($dt[0]+1)).($dt[0]+1);
}

function p31_register($pidana) {
	$dt = mysql_fetch_array(mysql_query(
		"SELECT a.no_surat 
		FROM t_p31 a
		LEFT JOIN t_p16 b ON a.kd_perkara = b.kd_perkara
		WHERE b.kd_pidana=$pidana AND a.tgl_dikeluarkan LIKE '".date("Y")."%' 
		ORDER BY a.no_surat DESC limit 1"));
	return str_repeat("0", 4 - strlen($dt[0]+1)).($dt[0]+1);
}

function p32_register($pidana) {
	$dt = mysql_fetch_array(mysql_query(
		"SELECT a.no_surat 
		FROM t_p32 a
		LEFT JOIN t_p16 b ON a.kd_perkara = b.kd_perkara
		WHERE b.kd_pidana=$pidana AND a.tgl_dikeluarkan LIKE '".date("Y")."%' 
		ORDER BY a.no_surat DESC limit 1"));
	return str_repeat("0", 4 - strlen($dt[0]+1)).($dt[0]+1);
}

function bb_register() {
	$dt = mysql_fetch_array(mysql_query(
		"SELECT no_reg_bukti 
		FROM t_bb
		WHERE b.kd_pidana=$pidana AND a.tgl_dikeluarkan LIKE '".date("Y")."%' 
		ORDER BY no_reg_bukti DESC limit 1"));
	return str_repeat("0", 4 - strlen($dt[0]+1)).($dt[0]+1);
}
//.......................................................

function tingkat_kesatuan($kesatuan) {
	$tingkat = explode(" ",$kesatuan);
	return strtolower($tingkat[0]);
}

function tembusan_p16($tingkat) {
	switch($tingkat) {
		case "polsek":
		case "polsekta":
			echo "1. YTH. KAJATI JATIM<br/>";
			echo "2. YTH. KAJARI SURABAYA (Sebagai laporan)<br/>";
			echo "3. YTH. POLRESTABES SURABAYA<br/>";
			echo "4. ARSIP";
		break;
		case "polrestabes":
			echo "1. YTH. KAJATI JATIM<br/>";
			echo "2. YTH. KAPOLDA JATIM<br/>";
			echo "3. YTH. KAJARI SURABAYA (Sebagai laporan)<br/>";
			echo "4. ARSIP";
		break;
		case "polda":
			echo "1. KAPOLRI<br/>";
			echo "2. YTH. KAJATI JATIM<br/>";
			echo "3. YTH. KAJARI SURABAYA (Sebagai laporan)<br/>";
			echo "4. ARSIP";
		break;
	}
}
?>
